package cn.kgc.biz.service;

import cn.kgc.biz.vo.HotelDetailsVo;
import cn.kgc.biz.vo.HotelVideoDescVo;
import cn.kgc.dto.Dto;
import cn.kgc.mapper.AreaDicMapper;
import cn.kgc.mapper.HotelFeatureMapper;
import cn.kgc.mapper.HotelMapper;
import cn.kgc.mapper.ImageMapper;
import cn.kgc.pojo.*;
import cn.kgc.util.DtoUtil;
import cn.kgc.vo.*;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Service
@Transactional
public class HotelServiceImpl implements HotelService {
    @Resource
    private HotelMapper hotelMapper;
    @Resource
    private ImageMapper imageMapper;
    @Resource
    private AreaDicMapper areaDicMapper;
    @Resource
    private HotelFeatureMapper hotelFeatureMapper;
    @Override
    public Dto getHotelVideodesc(Long hotelId) {
        List<HotelVideoVo> hotelVideoVoList=hotelMapper.getHotelVideodesc(hotelId);
        //List<HotelVideoDescVo> hotelVideoDescVoList=new ArrayList<>();
        HotelVideoDescVo hotelVideoDescVo=new HotelVideoDescVo();
        for (HotelVideoVo hvv:hotelVideoVoList){
//            hotelVideoDescVo.setId(hvv.getId());
            hotelVideoDescVo.setHotelName(hvv.getHotelName());
            String[] hotelFeatureList=hvv.getFeatureNames().split(",");
            hotelVideoDescVo.setHotelFeatureList(hotelFeatureList);
            if (hvv.getTradingAreaNames()!=null){
                String[] tradingAreaNameList=hvv.getTradingAreaNames().split(",");
                hotelVideoDescVo.setTradingAreaNameList(tradingAreaNameList);
            }
            //hotelVideoDescVoList.add(hotelVideoDescVo);
        }
        return DtoUtil.getSuccesWithData(hotelVideoDescVo);
    }

    @Override
    public Dto queryhoteldetails(Long hotelId) {
        List<HotelDescVo> hotelDescVoList=hotelMapper.queryhoteldetails(hotelId);
        HotelDetailsVo hotelDetailsVo=new HotelDetailsVo();
        hotelDetailsVo.setName("酒店介绍");
        hotelDetailsVo.setDescription(hotelDescVoList.get(0).getDetails());
        List<HotelDetailsVo> hotelDetailsVoList=new ArrayList<>();
        hotelDetailsVoList.add(hotelDetailsVo);
        for (HotelDescVo hotelDescVo:hotelDescVoList){
            HotelDetailsVo hdv=new HotelDetailsVo();
            hdv.setName(hotelDescVo.getName());
            hdv.setDescription(hotelDescVo.getDescription());
            hotelDetailsVoList.add(hdv);
        }
        return DtoUtil.getSuccesWithData(hotelDetailsVoList);
    }

    @Override
    public Dto queryHotelFacilities(Long hotelId) {
        HotelWithBLOBs hotelWithBLOBs=hotelMapper.selectByPrimaryKey(hotelId);
        String hotelFacilities=hotelWithBLOBs.getFacilities();
        return DtoUtil.getSuccesWithData(hotelFacilities);
    }

    @Override
    public Dto queryHotelPolicy(Long hotelId) {
        HotelWithBLOBs hotelWithBLOBs=hotelMapper.selectByPrimaryKey(hotelId);
        String hotelPolicy=hotelWithBLOBs.getHotelPolicy();
        return DtoUtil.getSuccesWithData(hotelPolicy);
    }

    @Override
    public Dto getImg(Long hotelId) {
        List<HotelImgVo> hotelImgVoList=imageMapper.getImgByHotelId(hotelId);
        return DtoUtil.getSuccesWithData(hotelImgVoList);
    }

    @Override
    public Dto queryHotCity(Long isChina) {
        List<HotCityVo> hotCityVoList=areaDicMapper.queryHotCityByIsChina(isChina);
        return DtoUtil.getSuccesWithData(hotCityVoList);
    }

    @Override
    public Dto queryHotelFeature() {
        List<FeatureVo> featureVoList=hotelFeatureMapper.queryHotelFeature();
        return DtoUtil.getSuccesWithData(featureVoList);
    }
}
